﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web.UI;
using GTS.Channel.Api.Entity;
using Pub.Class;
using GTS.Channel.Api.Helper;

namespace GTS.Channel.Api {
    /// <summary>
    /// VietnamSMS和IVR的MO MT MR接收数据接口
    /// </summary>
    public class Vietnam : ISMSIVR {
        /// <summary>
        /// SPCode
        /// </summary>
        public string SPCode = "Vietnam";
        /// <summary>
        /// SMS MO的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMOData() {
            //初始值
            ChannelDealData info = new ChannelDealData();
            info.SPCode = SPCode;
            info.SMSKey = 1;
            info.IsHidden = false;

            //接收值
            info.Mobile = Request2.GetQ("mobile").Trim();
            info.ReceiveQuery = Request2.GetQ("instruction").Trim();
            info.LinkID = Request2.GetQ("msgid").Trim();
            info.LongPhone = Request2.GetQ("shortcode").Trim();
            info.Telcoid = Request2.GetQ("telcoid").Trim();
            info.CountryCode = Request2.GetQ("countrycode").Trim();
            info.Price = Request2.GetQ("price").ToDecimal();
            info.Unit = Request2.GetQ("unit").Trim();
            info.Area = Request2.GetQ("area").Trim();
            info.PLMN = Request2.GetQ("plmn").Trim();
            string motime = Request2.GetQ("motime").Trim();
            if (motime.Length == 14) info.MODate = DateTime.ParseExact(motime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
            else if (motime.Length == 12) info.MODate = DateTime.ParseExact(motime, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
            else Base.WriteLog("mo时间错误：" + motime);
            if (info.Price <= 0) Base.WriteLog("mo金额错误：" + info.Price);

            if (info.Mobile.IsNullEmpty() || info.LinkID.IsNullEmpty() || info.ReceiveQuery.IsNullEmpty() || info.LongPhone.IsNullEmpty()) return null;

            info = Base.GetInfo(info);

            Pub.Class.Log.Write(Server2.GetMapPath("/logdetail/" + DateTime.Now.ToDate() + "_" + SPCode + ".txt"), "MO（" + DateTime.Now + "）：" + Request2.GetRawUrl());

            return info;
        }
        /// <summary>
        /// SMS MT的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMTData() {
            //初始值
            ChannelDealData info = new ChannelDealData();
            info.SPCode = SPCode;
            info.SMSKey = 3;

            //接收值
            info.SMSContent = Request2.GetQ("instruction").Trim();
            info.LinkID = Request2.GetQ("msgid").Trim();
            info.MRDate = DateTime.Now;
            info.ResponseStatus = 1;

            if (info.SMSContent == "SUCCESS") info.ResponseStatus = 1; else if (info.SMSContent == "FAILURE") info.ResponseStatus = 0;
      
            if (info.LinkID.IsNullEmpty()) return null;

            Pub.Class.Log.Write(Server2.GetMapPath("/logdetail/" + DateTime.Now.ToDate() + "_" + SPCode + ".txt"), "MT（" + DateTime.Now + "）：" + Request2.GetRawUrl());

            return info;
        }
        /// <summary>
        /// SMS MR的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMRData() {
          return null;
        }
        /// <summary>
        /// IVR的参数数据
        /// </summary>
        /// <returns></returns>
        public IVRDealData GetIVRMRData() {
            return null;
        }
        /// <summary>
        /// 输出消息
        /// </summary>
        /// <param name="res"></param>
        public void Output(ResultEnum res) {
            Msg.WriteEnd(res == ResultEnum.Success ? "0" : "1");
        }
    }
}

